package com.wwj.auction.admin.service.impl;

import com.wwj.auction.admin.entity.Store;
import com.wwj.auction.admin.entity.UserInfo;
import com.wwj.auction.admin.enums.StoreStatus;
import com.wwj.auction.admin.mapper.StoreMapper;
import com.wwj.auction.admin.mapper.UserInfoMapper;
import com.wwj.auction.admin.service.SafeScanService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wwj
 * @version 1.0
 * @date 2022/01/15 17:15
 */
@Service
public class SafeScanServiceImpl implements SafeScanService {

    @Resource
    private StoreMapper storeMapper;
    @Resource
    private UserInfoMapper userInfoMapper;

    @Override
    public void getOutToSeized() {
        List<Store> storeList = storeMapper.selectList(null);
        for (Store store : storeList) {
            Integer getOut = store.getGetOut();
            if (getOut > 10) {
                // 若违规记录超过10次，则查封店铺
                Integer userId = store.getUserId();
                UserInfo userInfo = userInfoMapper.selectById(userId);
                userInfo.setStoreStatus(StoreStatus.IS_SEALED.getStatus());
                userInfoMapper.updateById(userInfo);
            }
        }
    }
}
